<?php
class GradosController extends AppController {

	var $name = 'Grados';
	var $helpers = array('Access');
	
	function index() {
		$usuario_activo = $this->Access->getMy('username');
		//Verificacion de sesion del sistema		
		if(!$usuario_activo){
			$this->Session->setFlash(__('Por favor inicie sesion', true));
			$this->redirect(array('controller'=>'users','action' => 'login'));
		}
		$this->Grado->recursive = 0;
		$this->set('grados', $this->paginate());
	}

	function view($id = null) {
		$usuario_activo = $this->Access->getMy('username');
		//Verificacion de sesion del sistema		
		if(!$usuario_activo){
			$this->Session->setFlash(__('Por favor inicie sesion', true));
			$this->redirect(array('controller'=>'users','action' => 'login'));
		}
		if (!$id) {
			$this->Session->setFlash(__('Invalid grado', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('grado', $this->Grado->read(null, $id));
	}

	function add() {
		$usuario_activo = $this->Access->getMy('username');
		//Verificacion de sesion del sistema		
		if(!$usuario_activo){
			$this->Session->setFlash(__('Por favor inicie sesion', true));
			$this->redirect(array('controller'=>'users','action' => 'login'));
		}
		if (!empty($this->data)) {
			$this->Grado->create();
			if ($this->Grado->save($this->data)) {
				$this->Session->setFlash(__('The grado has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The grado could not be saved. Please, try again.', true));
			}
		}
	
	}

	function edit($id = null) {
		$usuario_activo = $this->Access->getMy('username');
		//Verificacion de sesion del sistema		
		if(!$usuario_activo){
			$this->Session->setFlash(__('Por favor inicie sesion', true));
			$this->redirect(array('controller'=>'users','action' => 'login'));
		}
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid grado', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Grado->save($this->data)) {
				$this->Session->setFlash(__('The grado has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The grado could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Grado->read(null, $id);
		}
		
	}

	function delete($id = null) {
		$usuario_activo = $this->Access->getMy('username');
		//Verificacion de sesion del sistema		
		if(!$usuario_activo){
			$this->Session->setFlash(__('Por favor inicie sesion', true));
			$this->redirect(array('controller'=>'users','action' => 'login'));
		}
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for grado', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Grado->delete($id)) {
			$this->Session->setFlash(__('Grado deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Grado was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>